<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<jsp:useBean id="utilities" class="masterpiece.util.Utilities" scope="session" />    
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Update Article</title>
<link rel="stylesheet" type="text/css" href="css/default.css" />
</head>
<body>
<%@ include file="top_menu.jsp" %>
<%int id = Integer.parseInt(request.getParameter("articleid"));
ResultSet rs = utilities.getUpdateArticleInformation(id);
rs.next();
%>
<form action="updatearticle2.jsp" method="post">
    <h1>Edit Article</h1>
    <dl>
      <dt>Editor's ePass:</dt>
      <dd><input type="text" name="ePass"/></dd>
      <dt>Headline:</dt>
      <dd><input type="text" name="headline" value="<%=rs.getClob("headline").getSubString(1,(int)rs.getClob("headline").length())%>"/></dd>
      <dt>Sub-Headline:</dt>
      <dd><input type="text" name="subheadline" value="<%=rs.getClob("sub_headline").getSubString(1,(int)rs.getClob("sub_headline").length())%>"/></dd>
      <dt>Section:</dt>
      <%int checkSection = rs.getInt("section"); %>
      <dd><select name = "section">
      		<option <%=(checkSection == 1 ? "selected=\"selected\"" : "")%> value="1">News</option>
      		<option <%=(checkSection == 2 ? "selected=\"selected\"" : "")%>  value="2">Op-Ed</option>
      		<option <%=(checkSection == 3 ? "selected=\"selected\"" : "")%>  value="3">LuteLife</option>
      		<option <%=(checkSection == 4 ? "selected=\"selected\"" : "")%>  value="4">International</option>
      		<option <%=(checkSection == 5 ? "selected=\"selected\"" : "")%>  value="5">Arts Entertainment</option>
      		<option <%=(checkSection == 6 ? "selected=\"selected\"" : "")%>  value="6">Sports</option>
      </select> </dd>
      <dt>Body:</dt>
      <dd><textarea name ="body">
      <%
      InputStream stream = rs.getClob("body").getAsciiStream();
      int c = stream.read();
      while( c != -1){
    	  out.write(c);
    	  c = stream.read();
      }
      %>
      </textarea></dd>
      <dt>Issue:</dt>
      <dd><select name = "issue">
      <%ResultSet rset = utilities.returnIssueDates();
      while (rset.next()){%>
      <option value="<%=rset.getDate(1)%>" <%=(rs.getDate("issue").equals(rset.getDate(1)) ? "selected=\"selected\"" : "")%>><%=rset.getDate(1)%></option>
      <%}%>
      </select></dd>
      <dt>Rank:</dt>
      <dd><input type="text" name ="rank" value="<%=rs.getInt("rank")%>"/></dd>
      <%int checkStatus = rs.getInt("status");%>
      <dt>Status:</dt>
      <dd><select name = "status">
      	<option <%=(checkStatus == 1 ? "selected=\"selected\"" : "")%> value="1">Draft</option>
      	<option <%=(checkStatus == 2 ? "selected=\"selected\"" : "")%> value="2">Revised</option>
      	<option <%=(checkStatus == 3 ? "selected=\"selected\"" : "")%> value="3">Candidate</option>
      	<option <%=(checkStatus == 4 ? "selected=\"selected\"" : "")%> value="4">Final</option>
      </select></dd>
      </dl>
      <input type="hidden" name="articleid" value="<%=id%>"/>
      <p class="buttons">
        <input type="submit" value="Submit"/>
      </p>
  </form>

</body>
</html>